<template>
  <OrderSeePage :backname="backname" :orderTitle="orderTitle">
    <template v-slot:OrderDetail>
      <li>
        订单号：<span>{{ info.order_sn }}</span>
      </li>
      <li>
        用户名称：<span>{{ info.user_name }}</span>
      </li>
      <li>
        下单日期：<span>{{ parseTime(info.created_at, "{y}-{m}-{d}") }}</span>
      </li>
      <li>
        配送日期：<span
          >{{ parseTime(info.send_time, "{y}-{m}-{d}") }}
          {{ send_time[info.send_time_id] }}
        </span>
      </li>
      <li v-if="show_original_order_data">
        原下单金额：<span>{{ info.original_should_money }}</span>
      </li>
      <li>
        下单金额：<span>{{ info.should_money }}</span>
      </li>
      <li v-if="show_original_order_data">
        原配送金额：<span>{{ info.original_send_money }}</span>
      </li>
      <li>
        配送金额：<span>{{ info.send_money }}</span>
      </li>
      <li>
        运费：<span>{{ info.delivery_fee }}</span>
      </li>
      <li>
        优惠金额：<span>{{ info.discount_money }}</span>
      </li>
    </template>

    <template v-slot:default>
      <div v-loading="listLoading">
        <Table>
          <template v-slot:Title>
            商品信息
          </template>
          <template v-slot:Table>
            <el-table
              ref="multipleTable"
              :data="list"
              element-loading-text="加载中"
              fit
              highlight-current-row
              :summary-method="getSummaries"
              show-summary
            >
              <el-table-column label="序号" prop="userId" width="80">
                <template slot-scope="scope">{{ scope.$index + 1 }}</template>
              </el-table-column>
              <el-table-column
                label="商品名称"
                prop="name"
                show-overflow-tooltip
              />
              <el-table-column label="单位" prop="unit" show-overflow-tooltip />
              <el-table-column
                label="下单数量"
                prop="order_num"
                show-overflow-tooltip
              />
              <el-table-column
                label="下单单价"
                prop="order_price"
                show-overflow-tooltip
              />
              <el-table-column label="下单金额" prop="" show-overflow-tooltip>
                <template slot-scope="scope">
                  {{
                    roundFloat(
                      multiplyFloat(scope.row.order_num, scope.row.order_price),
                      2
                    )
                  }}
                </template>
              </el-table-column>
              <el-table-column
                label="配送数量"
                prop="sort_num"
                show-overflow-tooltip
              />
              <el-table-column
                label="配送单价"
                prop="sort_price"
                show-overflow-tooltip
              />
              <el-table-column
                label="配送金额"
                prop="userId"
                show-overflow-tooltip
              >
                <template slot-scope="scope">
                  {{
                    roundFloat(
                      multiplyFloat(scope.row.sort_num, scope.row.sort_price),
                      2
                    )
                  }}
                </template>
              </el-table-column>
              <el-table-column
                label="备注"
                prop="remark"
                show-overflow-tooltip
              />
              <el-table-column
                label="管理操作"
                align="left"
                fixed="right"
                width="100"
                class-name="main_hei handle"
                class="handle"
              >
                <template slot-scope="scope">
                  <el-dropdown v-if="show_original_order_data">
                    <span class="el-dropdown-link" style="cursor: pointer">
                      原数据
                    </span>
                    <el-dropdown-menu slot="dropdown">
                      <el-dropdown-item>
                        <el-link style="color: rgb(17, 138, 178)"
                          >原下单数量：{{
                            scope.row.original_order_num
                          }}</el-link
                        >
                      </el-dropdown-item>
                      <el-dropdown-item>
                        <el-link style="color: rgb(17, 138, 178)"
                          >原下单单价：{{
                            scope.row.original_order_price
                          }}</el-link
                        >
                      </el-dropdown-item>
                      <el-dropdown-item>
                        <el-link style="color: rgb(17, 138, 178)"
                          >原下单金额：{{
                            scope.row.original_order_money
                          }}</el-link
                        >
                      </el-dropdown-item>
                      <el-dropdown-item>
                        <el-link style="color: rgb(17, 138, 178)"
                          >原配送数量：{{
                            scope.row.original_sort_num
                          }}</el-link
                        >
                      </el-dropdown-item>
                      <el-dropdown-item>
                        <el-link style="color: rgb(17, 138, 178)"
                          >原配送单价：{{
                            scope.row.original_sort_price
                          }}</el-link
                        >
                      </el-dropdown-item>
                      <el-dropdown-item>
                        <el-link style="color: rgb(17, 138, 178)"
                          >原配送金额：{{
                            scope.row.original_sort_money
                          }}</el-link
                        >
                      </el-dropdown-item>
                    </el-dropdown-menu>
                  </el-dropdown>
                </template>
              </el-table-column>
            </el-table>
          </template>
        </Table>
        <Table>
          <template v-slot:Title>
            生命周期
          </template>
          <template v-slot:Table>
            <el-table
              ref="multipleTable"
              :data="logs"
              element-loading-text="加载中"
              fit
              highlight-current-row
            >
              <el-table-column
                label="管理员"
                prop="admin.name"
                class-name="main_hei"
              />
              <el-table-column
                label="操作"
                prop="operate.name"
                class-name="main_hei"
              />
              <el-table-column
                label="内容"
                prop="content"
                class-name="main_hei"
              >
                <template slot-scope="scope">
                  <div
                    v-for="(content, index) in scope.row.content"
                    :key="index"
                    class="marginTop5 marginBottom5"
                  >
                    {{ content }}
                  </div>
                </template>
              </el-table-column>
              <el-table-column label="IP" prop="ip" class-name="main_hei" />
              <el-table-column
                label="时间"
                prop="created_at"
                class-name="main_hei"
              >
                <template slot-scope="scope">{{
                  parseTime(scope.row.created_at)
                }}</template>
              </el-table-column>
            </el-table>
          </template>
        </Table>
      </div>
    </template>
  </OrderSeePage>
</template>
<script>
import OrderSeePage from "@/components/OrderSeePage";
import Table from "@/components/OrderSeePage/table.vue";
import { parseTime, exportMethod, getNowMonth } from "@/utils/index";
import { multiplyFloat, roundFloat } from "@/utils/math.js";
import { get_empty_info } from "@/api/financial/finaicalOther";
import { mapGetters } from "vuex";
export default {
  components: {
    OrderSeePage,
    Table
  },
  data() {
    return {
      parseTime,
      multiplyFloat,
      roundFloat,
      backname: "其他用户对账",
      orderTitle: "订单信息",
      info: {},
      listLoading: false,
      list: [],
      send_time: [],
      logs: [],
      id: ""
    };
  },
  computed: {
    total() {
      let order_money = 0;
      let sort_money = 0;
      this.list.map(e => {
        order_money += parseFloat(
          this.roundFloat(this.multiplyFloat(e.order_num, e.order_price), 2)
        );
        sort_money += parseFloat(
          this.roundFloat(this.multiplyFloat(e.sort_num, e.sort_price), 2)
        );
      });
      order_money = this.roundFloat(order_money, 2);
      sort_money = this.roundFloat(sort_money, 2);
      return {
        sort_money,
        order_money
      };
    },
    ...mapGetters({
      show_original_order_data: "show_original_order_data"
    })
  },
  methods: {
    get_empty_info() {
      let data = { id: this.id };
      this.listLoading = true;
      get_empty_info(data).then(res => {
        if (res.errcode == 0) {
          let info = res.data.info;
          if (res.data.account_info) {
            info = res.data.account_info;
            info.order_list.map(e => {
              e.original_order_money = this.roundFloat(
                this.multiplyFloat(
                  e.original_order_num,
                  e.original_order_price
                ),
                2
              );
              e.original_sort_money = this.roundFloat(
                this.multiplyFloat(e.original_sort_num, e.original_sort_price),
                2
              );
            });
          } else {
            info.original_send_money = info.send_money;
            info.original_should_money = info.should_money;
            info.order_list.map(e => {
              e.original_order_num = e.order_num;
              e.original_order_price = e.order_price;
              e.original_order_money = this.roundFloat(
                this.multiplyFloat(e.order_num, e.order_price),
                2
              );

              e.original_sort_num = e.sort_num;
              e.original_sort_price = e.sort_price;
              e.original_sort_money = this.roundFloat(
                this.multiplyFloat(e.sort_num, e.sort_price),
                2
              );
            });
          }
          info.user_name = "";
          if (info.zid_info) {
            info.user_name = `${info.member.nickname}【${
              info.zid_info.nickname
            }】`;
          } else {
            info.user_name = `${info.member.nickname}`;
          }
          this.info = info;
          this.send_time = res.data.send_time;
          this.list = info.order_list;
          this.logs = res.data.logs;
        } else {
          this.$message.error(res.errmsg);
        }
        this.listLoading = false;
      });
    },
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        switch (index) {
          case 0:
            sums[index] = "合计";
            break;
          case 5:
            sums[index] = this.total.order_money;
            break;
          case 8:
            sums[index] = this.total.sort_money;
            break;
        }
      });
      return sums;
    }
  },
  created() {
    this.id = this.$route.params.id;
    this.get_empty_info();
  }
};
</script>
<style lang="scss" scoped></style>
